package subject_set.offer100;

/**
 * @author haomin
 * @date 2022/10/17 16:00
 **/
public class Offer33 {
    class Solution {
        public boolean verifyPostorder(int[] postorder) {
            return postOrd(postorder, 0 , postorder.length-1);
        }
        private boolean postOrd(int[] postorder, int l, int r){
            if(l > r) return true;

            int m = l;
            while(postorder[m] < postorder[r]) m++;
            int p = m;
            while(postorder[p] > postorder[r]) p++;
            return p == r && postOrd(postorder, l, m-1) && postOrd(postorder, m, r-1);
        }
    }
}